using System;
using System.Collections.Generic;
using System.Text;
using Barrage;
using Barrage.Meshes.Text;
using Spacedash.Logic;
using SlimDX;
using Barrage.Language;

namespace Spacedash.Game.Items
{
    class GUILapTimes : Item
    {
        const string TIMES = "TIMES";
        public const float SIZE_X = 250;
        public const float SIZE_Y = 150;
        TextBoxMesh textBoxMesh;
        Ship ship;
        Race race;
        public GUILapTimes(Vector2 position, Race race, Ship ship)
        {
            this.ship = ship;
            this.race = race;
            motion.Translation = new Vector3(position, 0);
            TextBoxDrawProperties tbdp = new TextBoxDrawProperties(TextAlignment.Left, new Vector2(SIZE_X, SIZE_Y), 0.25f, VerticalAlignment.Top, Vector2.Zero);
            textBoxMesh = new TextBoxMesh(BitmapFontManager.Fonts["Standard"], tbdp);
            textBoxMesh.FirstMaterial.Diffuse = (Color4)ship.Color;
            addMesh(textBoxMesh);
        }

        protected override void DoUpdate()
        {
            textBoxMesh.Text = LanguageManager.Texts[TIMES] + "\n";
            List<Lap> elapsedLaps = ship.ElapsedLaps;
            foreach (Lap lap in elapsedLaps.GetRange(Math.Max(0,elapsedLaps.Count-4),Math.Min(4,elapsedLaps.Count)))
            {
                textBoxMesh.Text += lap+"\n";
            }
            if (ship.State == ShipState.Running)
                textBoxMesh.Text += ship.CurrentLap;
            base.DoUpdate();
        }
    }
}
